<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>角色管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20" class="el-row-table">
        <el-col :span="12"
          ><div class="grid-content bg-purple">
            <el-input placeholder="请输入内容" clearable>
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input></div
        ></el-col>

        <el-col :span="4">
          <div class="grid-content bg-purple">
            <el-button type="success" @click="getRolesList">刷新</el-button>
          </div>
        </el-col>
      </el-row>

      <!-- 角色列表区域 -->
      <el-table border stripe width="100%" :data="rolesList">
        <el-table-column fixed label="序号" prop="id"> </el-table-column>
        <el-table-column fixed label="角色名" prop="note"> </el-table-column>
        <el-table-column fixed label="角色标识" prop="name"> </el-table-column>

        <el-table-column fixed label="操作">
          <!-- slot-scope="scope" -->
          <template slot-scope="scope">
            <!-- 第一个是查看详情按钮 -->
            <el-tooltip
              effect="dark"
              content="授予权限"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="primary"
                icon="el-icon-s-custom"
                circle
                @click="toAuthorize(scope.row.id)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.current"
        :page-sizes="[5, 10]"
        :page-size="queryInfo.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 删除角色对话框 -->
    <!-- <el-dialog
      title="删除角色"
      :visible.sync="removeRolesDialogVisible"
      width="30%"
    >
      <span>确定删除掉角色：{{ rolesForm.name }} 吗</span> -->
    <!-- 底部区 -->
    <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="removeRolesDialogVisible = false">关 闭</el-button>
        <el-button type="primary" @click="onRemoveRoles">确 定</el-button>
      </span>
    </el-dialog> -->
  </div>
</template>

<script>
import {
  lockRoles,
  unlockRoles,
  getRoles,
  pageRoles,
} from "@/api/rolesmanagement.js";
export default {
  data() {
    return {
      //获取角色列表的参数对象
      queryInfo: {
        current: 1,
        size: 5,
        name: "",
      },
      total: 0,
      rolesList: [],
      addrolesForm: {
        id: "", //角色ID
        name: "", //角色名
      },
      rolesForm: {
        id: "", //角色ID
        name: "", //角色名
      },
      addrolesFormRules: {
        name: [
          {
            required: true,
            message: "请输入角色名称",
            trigger: "blur",
          },
        ],
      },
      //添加角色窗口显示与隐藏
      addRolesDialogVisible: false,
      //删除角色窗口显示与隐藏
      removeRolesDialogVisible: false,
    };
  },
  created() {
    this.getRolesList();
  },
  methods: {
    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.size = newSize;
      this.getRolesList();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.current = newPage;
      this.getRolesList();
    },
    //获得角色列表
    async getRolesList() {
      const { data: res } = await pageRoles(
        this.queryInfo.current,
        this.queryInfo.size
      );

      this.rolesList = res.data.records;
      this.total = res.data.total;
    },

    toAuthorize(id) {
      localStorage.setItem("roleId", JSON.stringify(id));
      this.$router.push("/auth/role/warrant");
    },
  },
};
</script>

<style lang="less" scoped>
.breadcrumb {
  margin-bottom: 15px;
  font-size: 15px;
}
.box-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;
}
.el-row-table {
  margin-bottom: 15px !important;
}
.el-pagination {
  margin-top: 15px;
}
</style>